package com.example.multi_db.controller;

import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.multi_db.service.SyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description 测试接口
 * @Author lihw
 * @Date 2023/12/7 15:49
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    SyncService syncService;

    @GetMapping("msg")
    public String msg() {

        TestController bean = SpringUtil.getBean(this.getClass());
        bean.writeList();
        List<Object> objects = bean.readList();
        System.out.println("readList: {}" + objects.toString());

        return "succ";
    }

    @DS("source")
    public List<Object> readList() {
        return syncService.readList();
    }

    @DS("target")
    public void writeList() {
      syncService.writeList(null);
    }
}
